#include <vector>
#include <memory>
#include <initializer_list>
#include <iostream>
using namespace std;


class StringVector {
public:
	typedef std::vector<std::string>::size_type size_type;
	StringVector() {};
	StringVector(initializer_list<string> li) : _data(make_shared<std::vector<string> >(li))
	{
		cout << "initializer_list\n";
		cout << _data->size() << endl;
	}
	string push(const string & str)
	{
		_data->push_back(str);
		cout << "pushing\n";
		return "testing";
	}
	friend ostream & operator<<(ostream &os, const StringVector &str)
	{
		cout << "doing \n";
		if (str._data != nullptr)
		{
			for( auto & s : *(str._data) )
				os << s;
		}
		return os;
	}




private:
	std::shared_ptr<std::vector<string> > _data;
};


int main(int argc, char const *argv[])
{
	string str1 = "jintao";
	string str2 = "hello";
	StringVector strVec{"str1", "str2"};
	strVec.push(str2);
	cout << strVec <<endl;

	auto pshared = make_shared<decltype(strVec)>();
	auto ps1(pshared);
	cout << pshared.use_count() << endl;
	ps1 = nullptr;
		cout << pshared.use_count() << endl;

	return 0;
}



/*
#include <iostream>
#include <vector>
#include <initializer_list>
 
template <class T>
struct S {
    std::vector<T> v;
    S(std::initializer_list<T> l) : v(l) {
         std::cout << "constructed with a " << l.size() << "-element list\n";
    }
    void append(std::initializer_list<T> l) {
        v.insert(v.end(), l.begin(), l.end());
    }
    std::pair<const T*, std::size_t> c_arr() const {
        return {&v[0], v.size()};  // copy list-initialization in return statement
                                   // this is NOT a use of std::initializer_list
    }
};
 
template <typename T>
void templated_fn(T) {}
 
int main()
{
    S<int> s = {1, 2, 3, 4, 5}; // copy list-initialization
    s.append({6, 7, 8});      // list-initialization in function call
 
    std::cout << "The vector size is now " << s.c_arr().second << " ints:\n";
 
    for (auto n : s.v)
        std::cout << n << ' ';
    std::cout << '\n';
 
    std::cout << "Range-for over brace-init-list: \n";
 
    for (int x : {-1, -2, -3}) // the rule for auto makes this ranged-for work
        std::cout << x << ' ';
    std::cout << '\n';
 
    auto al = {10, 11, 12};   // special rule for auto
 
    std::cout << "The list bound to auto has size() = " << al.size() << '\n';
 
//    templated_fn({1, 2, 3}); // compiler error! "{1, 2, 3}" is not an expression,
                             // it has no type, and so T cannot be deduced
    templated_fn<std::initializer_list<int>>({1, 2, 3}); // OK
    templated_fn<std::vector<int>>({1, 2, 3});           // also OK
}
*/




